package com.mzx.customer.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mzx.customer.service.CustomerService;
import com.mzx.entity.Customer;

@Controller
@RequestMapping("/Customer")
public class CustomerController {
@Autowired
private CustomerService customerService;

			/*登录控制器*/
@PostMapping("/login.action")
public String login(Customer customer,HttpSession httpSession,Model model) {
	
	customer =customerService.login(customer);
	
	if(customer==null) {
		model.addAttribute("msg", "账号密码错误！");
		return "cuslogin";
		}
	System.out.println(customer);
		httpSession.setAttribute("customer",customer);
		return "forward:/Info/loadinfo.action";
}
			
			/*跳转注册*/
@GetMapping("/GotoRegist.action")
public String GotoRegist() {
	
	return "regist";
}
			/*注册控制器*/
@PostMapping("/Regist.action")
public String regist(Customer customer,HttpSession httpSession,Model model) {
	
	if((customerService.verifyCarcode(customer))==null) {
		customerService.regist(customer);
		model.addAttribute("msg", "注册成功！请登录！");
		return "cuslogin";
		
	}else {
		model.addAttribute("msg", "车辆大架号已存在！请重新输入！");
		return "regist";
		
	}
	
	
}
			/*跳转登录*/
@GetMapping("/GotoLogin.action")
public String GotoLogin() {
	
	return "cuslogin";
}
			/*退出登录*/
@GetMapping("/outlogin.action")
public  String outlogin(HttpSession session) {
	session.invalidate();
	return  "cuslogin";
	
}

}
